package com.jemaa.news.web;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.derby.drda.NetworkServerControl;


public class ServletInit extends HttpServlet{


	private static final long serialVersionUID = 1L;

	protected final Log logger = LogFactory.getLog(getClass());

	private NetworkServerControl server = null; 
	
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		
		try {
			server = new NetworkServerControl
			(InetAddress.getByName("ns353943.ovh.net"),1527);
			server.start(null);
			logger.info("-----------------------------------------------------");
			logger.info("--  SERVEUR DE BASE DE DONNEES DEMARRE             --");
			logger.info("-----------------------------------------------------");
		} catch (UnknownHostException e) {
			logger.fatal("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
			logger.fatal("!!  ALERTE ! ECHEC DE DEMARRAGE DE SERVEUR DE BASE DE DONNEES   !!");
			logger.fatal("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
			logger.fatal(e);
		} catch (Exception e) {
			logger.fatal("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
			logger.fatal("!!  ALERTE ! ECHEC DE DEMARRAGE DE SERVEUR DE BASE DE DONNEES   !!");
			logger.fatal("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
			logger.fatal(e);
		}
	
	}
	
	/**
	 * Destruction de la servlet.
	 */
	public void destroy() {

		try {
			// fin des services de Jobs
			server.shutdown();
		} catch (Exception e) {
			logger.fatal(e);
		}
	}



}
